//
//  PersonalProfileTableViewController.m
//  HYApp
//
//  Created by Jianbo Cai on 2020/8/21.
//  Copyright © 2020 Unidax. All rights reserved.
//

#import "PersonalProfileTableViewController.h"
#import "EditPhoneNumberTableViewController.h"
#import "ListAgreementsTableViewController.h"
#import "HYNetHelper.h"

@interface PersonalProfileTableViewController ()
@property (weak, nonatomic) IBOutlet UILabel *accountIdTitleLab;
@property (weak, nonatomic) IBOutlet UILabel *accountTypeTitleLab;
@property (weak, nonatomic) IBOutlet UILabel *emailTitleLab;
@property (weak, nonatomic) IBOutlet UILabel *phoneNumberTitleLab;
@property (weak, nonatomic) IBOutlet UILabel *referraTitleLab;
@property (weak, nonatomic) IBOutlet UILabel *agreementTitleLab;

@end

@implementation PersonalProfileTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView.tableFooterView = [[UIView alloc]init];
    self.tableView.separatorInset = UIEdgeInsetsZero;
    self.navigationItem.title = JFMainLocalizedString(@"myProfile.personal-information");
    WEAKSELF
    [HYNetHelper allUsers:^(JFResultVo *resultVo) {
        if (resultVo.errorNo == 0) {
            weakSelf.accountId.text = resultVo.results[@"account_id"];
            weakSelf.email.text = resultVo.results[@"email"];
            NSString * country_code =  [resultVo.results stringForKey:@"country_code"];
            NSString * mobile =  resultVo.results[@"mobile"];
            if([JFStringHelper isNotEmpty:country_code] && [JFStringHelper isNotEmpty:mobile]){
                weakSelf.phone.text = [NSString stringWithFormat:@"%@-%@",[resultVo.results stringForKey:@"country_code"],resultVo.results[@"mobile"]];
            }else{
                weakSelf.phone.text = @"--";
            }
          
            weakSelf.referralCode.text = resultVo.results[@"referral_code"];
            weakSelf.role.text =resultVo.results[@"account_tiers_id"][@"tier"];
        }
    }];
    
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self initLanguage];
}

#pragma mark - Table view data source

- (IBAction)editPhoneNumberAction:(id)sender {
    EditPhoneNumberTableViewController *vc = [[UIStoryboard storyboardWithName:@"User" bundle:nil]instantiateViewControllerWithIdentifier:@"EditPhoneNumberTableViewController"];;
    [self.navigationController pushViewController:vc animated:YES];
}

- (IBAction)referralAction:(id)sender {
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string = self.referralCode.text;
    [SLRemindView showMessage:JFMainLocalizedString(@"myAssets.copy-success") toView:self.view];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
{
    if (indexPath.row == 5) {
        ListAgreementsTableViewController *vc = [[UIStoryboard storyboardWithName:@"User" bundle:nil]instantiateViewControllerWithIdentifier:@"ListAgreementsTableViewController"];;
        [self.navigationController pushViewController:vc animated:YES];
    }
}



-(void)initLanguage{
    self.accountIdTitleLab.text  = JFMainLocalizedString(@"bank.account-number");
    self.accountTypeTitleLab.text  = JFMainLocalizedString(@"bank.account-type");
    self.emailTitleLab.text  = JFMainLocalizedString(@"myProfile.email");
    self.phoneNumberTitleLab.text  = JFMainLocalizedString(@"myProfile.phone-number");
    self.referraTitleLab.text  = JFMainLocalizedString(@"myProfile.Referral");
    self.agreementTitleLab.text  = JFMainLocalizedString(@"myProfile.SignedAgreements");
}


@end
